/**
 * Author: grx
 * Description: 开屏动画页面
 */
package com.example.parallelandroid;

import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.widget.ImageView;

public class SplashActivity extends AppCompatActivity {

    private ImageView ivSplash;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_splash);

        Constant.logger.info("Parallel启动");
        // 获取控件对象
        ivSplash = findViewById(R.id.iv_splash);
        // 消除APP该Activity界面标题栏
        ActionBar actionBar = getSupportActionBar();
        if (actionBar != null) {
            actionBar.hide();
        }
        AlphaAnimation animation = new AlphaAnimation(0.3f, 1.0f);
        animation.setDuration(3000); // 设置简单动画的显示时间
        ivSplash.startAnimation(animation);
        animation.setAnimationListener(new Animation.AnimationListener() {
            @Override
            public void onAnimationStart(Animation animation) {
                ivSplash.setBackgroundResource(R.mipmap.splash);// 开机图片
            }

            @Override
            public void onAnimationEnd(Animation animation) {
                /**
                 * 动画结束后跳转到别的页面
                 */
                startActivity(new Intent(SplashActivity.this, MainActivity.class)); //动画开屏后返回APP登录界面
                Constant.logger.info("Jump from SplashActivity to MainActivity");
                finish(); //结束SplashActivity
            }

            @Override
            public void onAnimationRepeat(Animation animation) {

            }
        });
    }
}